package com.project.nimsen.service.impl;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Repository;

import com.project.nimsen.dao.IBaseDao;
import com.project.nimsen.dto.UrlinfoDto;
import com.project.nimsen.service.IUrlinfoService;
import com.project.jdbc.dao.IBaseJdbcDao;
import com.project.jdbc.service.BaseServiceImpl;
import com.project.jdbc.utils.Finder;
import com.project.jdbc.utils.Page;
@Repository("urlinfoService")
public class UrlinfoServiceImpl extends BaseServiceImpl implements
		IUrlinfoService {
	@Resource
	IBaseDao baseDao;
	public IBaseJdbcDao getBaseDao() {
		return baseDao;
	}
	public List<Map<String, Object>> findUrlListByDto(UrlinfoDto dto)
			throws Exception {
		Finder finder = new Finder("select id,url,urlname,urldesc,urloutid,urloutable,createUser"
			+ ",createTime,active from urlinfo where active!=1 and urloutid=:urloutid and "
			+ "urloutable=:urloutable");
		finder.setParam("urloutid", dto.getUrloutid());
		finder.setParam("urloutable", dto.getUrloutable());
		return baseDao.queryForList(finder);
	}
	public List<Map<String, Object>> findTagUrlByDto(UrlinfoDto dto)
			throws Exception {
		Finder finder = new Finder("select id,url,urlname,urldesc,urloutid,urloutable,createUser,"
			+ "createTime,active from urlinfo where active!=1");
		if(StringUtils.isNotBlank(dto.getUrloutable())){
			finder.append(" and urloutable=:urloutable");
			finder.setParam("urloutable", dto.getUrloutable());
		}
		if(StringUtils.isNotBlank(dto.getUrloutid())){
			finder.append(" and urloutid=:urloutid");
			finder.setParam("urloutid", dto.getUrloutid());
		}
		//排序
		finder.append(" order by createTime ").append(dto.getOrderType());
		//当查询全部类型的附件时
		if(dto.getNum()<1)
			return baseDao.queryForList(finder);
		Page page = new Page(1);
		page.setPageSize(dto.getNum());
		return baseDao.queryForList(finder, page);
	}
}
